package com.weng.cloud.service8881.mybatis.controller;

import com.weng.cloud.commons.base.JsonUtil;
import com.weng.cloud.service8881.mybatis.entity.PlayerEntity;
import com.weng.cloud.service8881.mybatis.mapper.PlayerMapper;
import com.weng.cloud.service8881.mybatis.service.PlayerService;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;

/**
 * @Author: weng
 * @Date: 2022/3/14
 * @Description: com.weng.cloud.service8881.mybatis
 */
@RestController
public class MyBatisController {

    @Resource
    private PlayerMapper playerMapper;

    @Resource
    private PlayerService playerService;

    @GetMapping("/testMyBatis")
    public String testMyBatis(){
        List<PlayerEntity> players = this.playerMapper.list();
        return JsonUtil.toText(players);
    }

    @GetMapping("/testSQLBuilder/{id}")
    public String testSQLBuilder(@PathVariable String id){
        List<PlayerEntity> players = this.playerMapper.testSQLBuilder(id);
        return JsonUtil.toText(players);
    }

    @GetMapping("/testTransactional")
    public String testTransactional(){
        List<PlayerEntity> players = new ArrayList<>();
        players.add(new PlayerEntity(12,"adams"));
        players.add(new PlayerEntity(0,"westbrook"));
        players.add(new PlayerEntity(13,"harden"));
//        return "@Transactional执行完毕 -> "+this.playerService.testTransactional(players);
        return "@Transactional执行完毕 -> "+this.playerService.testTransactionalInner(players);
    }
}
